package com.example.instantmessage.login;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.instantmessage.MainActivity;
import com.example.instantmessage.R;
import com.example.instantmessage.signature.GenerateTestUserSig;
import com.tencent.imsdk.relationship.UserInfo;
import com.tencent.imsdk.v2.V2TIMCallback;
import com.tencent.imsdk.v2.V2TIMManager;

public class LoginActivity extends AppCompatActivity {
    private TextView tvAccount,tvPwd;
    private EditText etAccount,etPwd;
    private Button btnLogin;

    public static String userId = "张三";

    private static final String TAG = LoginActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        tvAccount = findViewById(R.id.account_tv_login_activity);
//        tvPwd = findViewById(R.id.pwd_tv_login_activity);
        etAccount = findViewById(R.id.account_et_login_activity);
//        etPwd = findViewById(R.id.pwd_et_login_activity);
        btnLogin = findViewById(R.id.login_btn_login_activity);

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                etAccount.getText().toString();
                login();
            }
        });


//
//        etAccount.setText(UserInfo.getInstance().getUserId());
//
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//        Utils.checkPermission(this);
//
//        btnLogin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                UserInfo.getInstance().setUserId(etAccount.getText().toString());
//                String userSig = GenerateTestUserSig.genTestUserSig(etAccount.getText().toString());
//                UserInfo.getInstance().setUserSig(userSig);
//
//                V2TIMManager.getInstance().login(etAccount.getText().toString(),userSig, new V2TIMCallback() {
//                    @Override
//                    public void onSuccess() {
//                        UserInfo.getInstance().setAutoLogin(true);
//                        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
//                        startActivity(intent);
//                        finish();
//
//                    }
//
//                    @Override
//                    public void onError(int code, String desc) {
//                        runOnUiThread(new Runnable() {
//                            public void run() {
////                                ToastUtil.toastLongMessage(getString(R.string.failed_login_tip) + ", errCode = " + code + ", errInfo = " + desc);
//                                Toast.makeText(LoginActivity.this,getString(R.string.failed_login_tip) + ", errCode = " + code + ", errInfo = " + desc,Toast.LENGTH_SHORT).show();
//                            }
//                        });
//                        Log.i(TAG, "imLogin errorCode = " + code + ", errorInfo = " + desc);
//
//                    }
//                });
//            }
//        });



    }

    public  void login(){
        V2TIMManager.getInstance().login(userId, GenerateTestUserSig.genTestUserSig(userId), new V2TIMCallback() {
            @Override
            public void onSuccess() {

                Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                startActivity(intent);
                Log.e("====","onSuccess");
                System.out.println("11111 loginsu");
            }

            @Override
            public void onError(int code, String desc) {
                Log.e("====","onError");
                System.out.println("11111 loginFail");
            }
        });
    }
}